package com.gxa.ehome.service.impl;


import com.gxa.ehome.mapper.SysUserMapper;
import com.gxa.ehome.pojo.SysUser;
import com.gxa.ehome.service.SysUserService;
import com.gxa.ehome.util.MD5Creater;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {
    @Resource
    SysUserMapper sysUserMapper=null;

    @Override
    public boolean login(String jobNumber,String password) {
        SysUser regiester = sysUserMapper.regiester(jobNumber, MD5Creater.encode(password+jobNumber));
        if (regiester!=null){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public void deleteById(Integer id) {
        sysUserMapper.deleteById(id);

    }

    @Override
    public void register(SysUser sysUser) {

    }

    @Override
    public List<SysUser> findAll() {
        List<SysUser> all = sysUserMapper.findAll();
        System.out.println(all);
        return all;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,readOnly = true)
    public SysUser selectById(Integer id) {
        SysUser byId = sysUserMapper.findById(id);
        return byId;
    }

    @Override
    public void save(SysUser sysUser) {
        sysUserMapper.save(sysUser);
    }

    @Override
    public boolean findByJobNumber(String jobNumber) {
        boolean byJobNumBer = sysUserMapper.findByJobNumBer(jobNumber);
        return byJobNumBer;
    }

    @Override
    public void update(SysUser sysUser) {
        sysUserMapper.update(sysUser);
    }

    @Override
    public List<SysUser> findByPage(Integer page, Integer limit) {
        List<SysUser> allByPage = sysUserMapper.findAllByPage(page, limit);
        return allByPage;
    }


}
